package entry30.ref;

import java.util.HashMap;
import java.util.Map;

public enum Operation {
	PLUS {
		public int apply(int first, int last) {
			return first + last;
		}
	},
	MINUS {
		public int apply(int first, int last) {
			return first - last;
		}

	},
	TIMES {
		public int apply(int first, int last) {
			return first * last;
		}
	},
	DEVIDE {
		public int apply(int first, int last) {
			return first / last;
		}
	};

	private static Map<String, Operation> map = new HashMap<String, Operation>();
	static {
		map.put("+", PLUS);
		map.put("-", MINUS);
		map.put("*", TIMES);
		map.put("/", DEVIDE);
	}
	
	public static Operation op(String key) {
		return map.get(key);
	}
	
	public abstract int apply(int first, int last);
}
